#include "SeqStack.h"

void initStack(SeqStack& S)
{
	S.elem = (SElemType*)malloc(sizeof(initSize * sizeof(SElemType)));
	S.maxSize - initSize;
	S.top = -1;
}

void overflowProcess(SeqStack& S)
{
	S.maxSize = S.maxSize + increments;
	SElemType* newArray = (SElemType*)malloc(S.maxSize * sizeof(SElemType));
	for (int i = 0; i <= S.top; i++)
	{
		newArray[i] = S.elem[i];
	}
	free(S.elem);
	S.elem = newArray;
}

bool stackFull(SeqStack& S)
{
	return S.top >= S.maxSize - 1;
}

bool Push(SeqStack& S, SElemType x)
{
	if (stackFull(S))
	{
		overflowProcess(S);
	}
	S.elem[++S.top] = x;
	return true;
}

bool Pop(SeqStack& S, SElemType& x)
{
	if (S.top == -1)
	{
		return false;
	}
	x = S.elem[S.top--];
	return true;
}

bool stackEmpty(SeqStack& S)
{
	return S.top == -1;
}

bool getTop(SeqStack& S, SElemType& x)
{
	if (S.top == -1)
	{
		return false;
	}
	x = S.elem[S.top];
	return true;
}

int stackSize(SeqStack& S)
{
	return S.top + 1;
}